package com.dai.zhenfujin.my.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dai.zhenfujin.R;
import com.dai.zhenfujin.my.bean.MyBean;

import java.util.List;

public class MyAdapter extends BaseAdapter {
    private Context context;
    private List<MyBean> beans;
    private LayoutInflater inflater;

    public MyAdapter(Context context, List<MyBean> beans) {
        this.context = context;
        this.beans = beans;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return beans.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder ;
            if (convertView == null){
                holder = new ViewHolder();
                convertView = inflater.inflate( R.layout.my_listview,null);
                holder.tvCompany = convertView.findViewById(R.id.my_listview_company);
                holder.tvPrice = convertView.findViewById(R.id.my_listview_price);
                holder.tvResidence = convertView.findViewById(R.id.my_listview_residence);
                holder.tvSite = convertView.findViewById(R.id.my_listview_site);

                convertView.setTag(holder);
        }else {
                holder = (ViewHolder) convertView.getTag();
            }

            MyBean bean = beans.get(position);
            holder.tvCompany.setText(bean.getCompany());
            holder.tvPrice.setText(bean.getPrice());
            holder.tvResidence.setText(bean.getResidence());
            holder.tvSite.setText(bean.getSite());

        return convertView;
    }

    class ViewHolder{
        TextView tvCompany,tvPrice,tvResidence,tvSite;
        ImageView ivImg,ivDelete;
    }
}
